<?php

/**
 * 第三方订单日志表
 * @author linan
 */
namespace App\Model\PssModel;

use App\Model\BaseModel\BasePssModel;
use App\Service\Code\Normal;

class OrderPullLog extends BasePssModel
{
     /**
     * 订单取消处理成功 状态
     */
    const STATUS_CANCLE_SUC = 6;
    /**
     * 订单取消处理失败 状态
     */
    const STATUS_CANCLE_FAIL = 7;

    public $table = 'order_pull_log';

    //0-未处理，1-订单创建成功,2-订单支付成功,3-订单创建失败,4-订单支付失败,5-订单取消未处理,6-订单取消处理成功,7-订单取消处理失败
    public static $statusTextArr = [
        ['status' => 0, 'statusName' => '未处理'],
        ['status' => 1, 'statusName' => '订单创建成功'],
        ['status' => 2, 'statusName' => '订单支付成功'],
        ['status' => 3, 'statusName' => '订单创建失败'],
        ['status' => 4, 'statusName' => '订单支付失败'],
        ['status' => 5, 'statusName' => '订单取消未处理'],
        ['status' => 6, 'statusName' => '订单取消处理成功'],
        ['status' => 7, 'statusName' => '订单取消处理失败'],
    ];

    public static $pushStatusTextArr = [
        '0' => '待处理',
        '1' => '已处理推送',
        '2' => '获取面单失败或清关材料失败',
        '3' => '商品未授权',
        '4' => '拼多多退款',
        '5' => '拼多多已发货'
    ];

    /**
     * 写入订单日志数据
     * @param array $param
     */
    public function addLog( $param = [] )
    {
        $info = $this->info([
            ['bid', '=', $param['bid']],
            ['order_sn', '=', $param['order_sn']],
        ]);
        if (!empty($info)) {
            return Normal::returnCode(Normal::FAIL, "订单号已存在");
        }
        $data = [
            'bid'               => $param['bid'],
            'order_sn'          => $param['order_sn'],
            'contents'          => $param['contents'],
            'is_pay_declare'    => $param['is_pay_declare']??1,
            'cd'                => time(),
        ];
       
        if( isset($param['pdd_status']) ) {
            $data['pdd_status'] = $param['pdd_status'];
        }
        
        if ($this->add($data)) {
            return Normal::returnCode(Normal::SUC, "写入订单日志数据成功");
        }
        return Normal::returnCode(Normal::FAIL, "写入订单日志数据失败");
    }
}
